'use strict';

/**
 * @ngdoc directive
 * @name webApp.directive:slideBox
 * @description
 * # slideBox
 */
angular.module('webApp')
  .directive('slideBox', function ($animate,jqLite,cookie) {
  return {
    templateUrl: 'views/homeSlideBox.html',
    restrict: 'AE',
    replace: false,
    scope: {
      slideBoxData: '=slideBoxData'
    },
    compile: function(tele,tattr){
      return{
        pre: function($scope,tele,tattr){
          //写入新闻id的cookie
          $scope.setId = function(id){
            cookie.setCookie('newsId',id);
          }
        },
        post: function($scope,iele,iattr){
          $scope.slideFunc = function(index){
            jqLite.$('slideAbstractNews').removeClass('slideAbstractNews-add');
            jqLite.$('slideAbstractNews').removeClass('show');
            $animate['addClass'](
              jqLite.$('slideAbstractNews').eq(index),'slideAbstractNews-add',
              jqLite.$('slideAbstractNews').removeClass('slideAbstractNews-add'),
              jqLite.$('slideAbstractNews').removeClass('slideAbstractNewsDone'),
              jqLite.$('slideAbstractNews').eq(index).addClass('slideAbstractNewsDone')
            );
          }
        }
      }
    }
  };
});
